home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / ppp / dp-2.3 / sts / baudext.c next >
Encoding:
C/C++ Source or Header  |  1993-01-19  |  1.5 KB  |  80 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <errno.h>
  4.  
  5. #include <sys/file.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/ctio.h>
  8.  
  9. char *argv0;
  10.  
  11. main(argc, argv)
  12. int argc;
  13. char **argv;
  14. {
  15.     int c, i;
  16.     extern int optind;
  17.     extern char *optarg;
  18.     int baudext = -1;
  19.     argv0 = *argv;
  20.     while ((c = getopt(argc, argv, "yn10")) != EOF)
  21.     switch (c) {
  22.      case 'y':
  23.      case '1':
  24.         baudext = 1;
  25.         break;
  26.      case 'n':
  27.      case '0':
  28.         baudext = 0;
  29.         break;
  30.     }
  31.     if (baudext < 0) {
  32.     fprintf(stderr, "%s: can't read baud extension factor, must set using -y or -n");
  33.     exit(1);
  34.     }
  35.     for (i = optind ; i < argc ; i++)
  36.     ttyext(argv[i], baudext);
  37.     exit(0);
  38. }
  39.  
  40. char *concatlist[] = { "", "/dev/", "/dev/tty", (char *)0 };
  41.  
  42. ttyext(tty, ext)
  43. char *tty;
  44. {
  45.     int f;
  46.     char ttyname[128];
  47.     char **cl;
  48.     extern int erno;
  49.  
  50.     for (cl = concatlist ; *cl ; cl++) {
  51.     (void)sprintf(ttyname, "%s%s", *cl, tty);
  52.  
  53.     if ((f = open(ttyname, O_RDWR|O_NDELAY)) < 0) {
  54.         if (errno == ENOENT)
  55.         continue;
  56.         fprintf(stderr, "%s: ", argv0);
  57.         perror(ttyname);
  58.         return;
  59.     }
  60.     break;
  61.     }
  62.     if (!*cl) {
  63.     fprintf(stderr, "%s: ", argv0);
  64.     perror(tty);
  65.     return;
  66.     }
  67.     if (ext >= 0) {
  68.     if (ioctl(f, STSBAUDEXTEN, &ext) < 0) {
  69.         fprintf(stderr, "%s: %s: ", argv0, ttyname);
  70.         perror("Central Data Baud Extension ioctl failed");
  71.     }
  72.     }
  73.     else {
  74.     /*
  75.      * There should be a way to read the baud extension factor.
  76.      * With the current firmware, this is not possible.
  77.      */
  78.     }
  79. }
  80.